package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.PermissionDao;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/*
* 权限管理
* */
@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;
    //添加权限
    @Override
    public void add(Permission permission) {
        //查询该权限关键字是否存在
        String keyword = permission.getKeyword();
            long count = permissionDao.findByKeyword(keyword);
            if (count > 0){
                //权限已存在
                throw  new RuntimeException("该权限已存在，无法添加");
            }else {
                //添加权限
                permission.setCreateDate(new Date());
                permissionDao.add(permission);

            }
    }
}
